#include <stdio.h>

/*
	局部变量

	f1的汇编代码与使用全局的代码完全相同。main会有相应的变化。
	f1可以返回位于任意地址的任意值，这个体现了指针的重要作用。

	C++的引用(指针)/reference的作用与C pointer(指针)相同。
 */

void f1(int x, int y, int * sum, int * product)
{
	*sum = x + y;
	*product = x * y;
}

void main()
{
	int sum, product;

	f1(123, 456, &sum, &product);
	printf("sum=%d, product=%d\n", sum, product);	// sum=579, product=56088
}

#if 0
/*
 * intel
 */
0000000000001169 <f1>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp
    1171:	89 7d fc             	mov    %edi,-0x4(%rbp)
    1174:	89 75 f8             	mov    %esi,-0x8(%rbp)
    1177:	48 89 55 f0          	mov    %rdx,-0x10(%rbp)
    117b:	48 89 4d e8          	mov    %rcx,-0x18(%rbp)
    117f:	8b 55 fc             	mov    -0x4(%rbp),%edx
    1182:	8b 45 f8             	mov    -0x8(%rbp),%eax
    1185:	01 c2                	add    %eax,%edx
    1187:	48 8b 45 f0          	mov    -0x10(%rbp),%rax
    118b:	89 10                	mov    %edx,(%rax)
    118d:	8b 45 fc             	mov    -0x4(%rbp),%eax
    1190:	0f af 45 f8          	imul   -0x8(%rbp),%eax
    1194:	89 c2                	mov    %eax,%edx
    1196:	48 8b 45 e8          	mov    -0x18(%rbp),%rax
    119a:	89 10                	mov    %edx,(%rax)
    119c:	90                   	nop
    119d:	5d                   	pop    %rbp
    119e:	c3                   	retq   

000000000000119f <main>:
    119f:	f3 0f 1e fa          	endbr64 
    11a3:	55                   	push   %rbp
    11a4:	48 89 e5             	mov    %rsp,%rbp
    11a7:	48 83 ec 10          	sub    $0x10,%rsp
    11ab:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11b2:	00 00 
    11b4:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    11b8:	31 c0                	xor    %eax,%eax
    11ba:	48 8d 55 f4          	lea    -0xc(%rbp),%rdx
    11be:	48 8d 45 f0          	lea    -0x10(%rbp),%rax
    11c2:	48 89 d1             	mov    %rdx,%rcx
    11c5:	48 89 c2             	mov    %rax,%rdx
    11c8:	be c8 01 00 00       	mov    $0x1c8,%esi
    11cd:	bf 7b 00 00 00       	mov    $0x7b,%edi
    11d2:	e8 92 ff ff ff       	callq  1169 <f1>
    11d7:	8b 55 f4             	mov    -0xc(%rbp),%edx
    11da:	8b 45 f0             	mov    -0x10(%rbp),%eax
    11dd:	89 c6                	mov    %eax,%esi
    11df:	48 8d 3d 1e 0e 00 00 	lea    0xe1e(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    11e6:	b8 00 00 00 00       	mov    $0x0,%eax
    11eb:	e8 80 fe ff ff       	callq  1070 <printf@plt>
    11f0:	90                   	nop
    11f1:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    11f5:	64 48 33 04 25 28 00 	xor    %fs:0x28,%rax
    11fc:	00 00 
    11fe:	74 05                	je     1205 <main+0x66>
    1200:	e8 5b fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    1205:	c9                   	leaveq 
    1206:	c3                   	retq   
    1207:	66 0f 1f 84 00 00 00 	nopw   0x0(%rax,%rax,1)
    120e:	00 00 

/*
 * arm
 */

000000000040055c <f1>:
  40055c:	d10083ff 	sub	sp, sp, #0x20
  400560:	b9001fe0 	str	w0, [sp, #28]
  400564:	b9001be1 	str	w1, [sp, #24]
  400568:	f9000be2 	str	x2, [sp, #16]
  40056c:	f90007e3 	str	x3, [sp, #8]
  400570:	b9401fe1 	ldr	w1, [sp, #28]
  400574:	b9401be0 	ldr	w0, [sp, #24]
  400578:	0b000021 	add	w1, w1, w0
  40057c:	f9400be0 	ldr	x0, [sp, #16]
  400580:	b9000001 	str	w1, [x0]
  400584:	b9401fe1 	ldr	w1, [sp, #28]
  400588:	b9401be0 	ldr	w0, [sp, #24]
  40058c:	1b007c21 	mul	w1, w1, w0
  400590:	f94007e0 	ldr	x0, [sp, #8]
  400594:	b9000001 	str	w1, [x0]
  400598:	d503201f 	nop
  40059c:	910083ff 	add	sp, sp, #0x20
  4005a0:	d65f03c0 	ret

00000000004005a4 <main>:
  4005a4:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  4005a8:	910003fd 	mov	x29, sp
  4005ac:	910063a1 	add	x1, x29, #0x18
  4005b0:	910073a0 	add	x0, x29, #0x1c
  4005b4:	aa0103e3 	mov	x3, x1
  4005b8:	aa0003e2 	mov	x2, x0
  4005bc:	52803901 	mov	w1, #0x1c8                 	// #456
  4005c0:	52800f60 	mov	w0, #0x7b                  	// #123
  4005c4:	97ffffe6 	bl	40055c <f1>
  4005c8:	b9401fa1 	ldr	w1, [x29, #28]
  4005cc:	b9401ba2 	ldr	w2, [x29, #24]
  4005d0:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005d4:	911a6000 	add	x0, x0, #0x698
  4005d8:	97ffff9e 	bl	400450 <printf@plt>
  4005dc:	d503201f 	nop
  4005e0:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4005e4:	d65f03c0 	ret


#endif

